package com.kc.business.service.impl;

import com.kc.business.domain.BizUser;
import com.kc.business.domain.dto.BizRegisterUserInfoDTO;
import com.kc.business.mapper.BizUserMapper;
import com.kc.business.service.IBizUserService;
import com.kc.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * TODO
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/9/10
 */
@Service
public class BizUserServiceImpl implements IBizUserService {

    @Autowired
    BizUserMapper bizUserMapper;

    @Override
    public List<BizUser> getList(BizUser bizUser) {
        return bizUserMapper.select(bizUser);
    }


    @Override
    public int edit(BizUser bizUser) {
        return bizUserMapper.updateByPrimaryKeySelective(bizUser);
    }

    @Override
    public List<BizRegisterUserInfoDTO> getRegisterUserList(BizUser user) {
        List<BizRegisterUserInfoDTO> bizRegisterUserInfoDTOS = bizUserMapper.getRegisterUserList(user);
        bizRegisterUserInfoDTOS.forEach(bizRegisterUserInfoDTO -> {
            if(!bizRegisterUserInfoDTO.getFaceStatus().equals(1)){
                bizRegisterUserInfoDTO.setFaceStatus(0);
            }
            BizUser bizUser = new BizUser();
            bizUser.setPId(bizRegisterUserInfoDTO.getId());
            bizRegisterUserInfoDTO.setAgentNum(bizUserMapper.selectCount(bizUser));
        });
        return bizRegisterUserInfoDTOS;
    }

    @Override
    public Integer setUserPassword(Integer userId) {
        BizUser user  = bizUserMapper.selectByPrimaryKey(9);
        if(user == null || StringUtils.isEmpty(user.getPassword())){
            return 0;
        }
        BizUser bizUser = new BizUser();
        bizUser.setId(userId);
        bizUser.setPassword(user.getPassword());
        return bizUserMapper.updateByPrimaryKeySelective(bizUser);
    }
}
